package com.ysxsoft.wdg.adapter;

import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.bean.DiscussBean;
import com.ysxsoft.wdg.constant.MCConfig;
import com.ysxsoft.wdg.util.ViewUtils;
import com.ysxsoft.wdg.view.EStarView;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import cn.bingoogolapple.photopicker.activity.BGAPhotoPreviewActivity;
import cn.bingoogolapple.photopicker.widget.BGANinePhotoLayout;

public class PingLunAdapter extends BaseQuickAdapter<DiscussBean,BaseViewHolder> {


    public PingLunAdapter(int layoutResId) {
        super(layoutResId);
    }

    public void clear(){
        getData().clear();
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseViewHolder helper, DiscussBean item) {
        helper.setText(R.id.tv_pl_nick, item.getNickname());
        helper.setText(R.id.tv_pl_content, item.getContent());
        helper.setText(R.id.tv_time, item.getAddtime());
        ViewUtils.loadCircleImage(mContext,item.getAvatar(), (ImageView) helper.getView(R.id.iv_pl_tx));
        EStarView view=helper.getView(R.id.starView);
        view.setStar(item.getScore());

       BGANinePhotoLayout ninePhotoLayout = helper.getView(R.id.photos);
       ninePhotoLayout.setData((ArrayList<String>) item.getPic());
        ninePhotoLayout.setDelegate(new BGANinePhotoLayout.Delegate() {
            @Override
            public void onClickNinePhotoItem(BGANinePhotoLayout ninePhotoLayout, View view, int position, String model, List<String> models) {
                File downloadDir = new File(MCConfig.PICTURE_DIR);
                BGAPhotoPreviewActivity.IntentBuilder photoPreviewIntentBuilder = new BGAPhotoPreviewActivity.IntentBuilder(mContext)
                        .saveImgDir(downloadDir); // 保存图片的目录，如果传 null，则没有保存图片功能
                photoPreviewIntentBuilder
                        .previewPhotos((ArrayList<String>) models).currentPosition(position); // 当前预览图片的索引
                mContext.startActivity(photoPreviewIntentBuilder.build());
            }
        });

    }
}
